// pages/my/set/system/system.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        checked: false,
        checke: false,
        check: false,
        chec: false,
        che: false,
    },
    onChange({ detail }) {
        var that = this;
        // 需要手动对 checked 状态进行更新
            wx.authorize({
                scope: 'scope.userLocation',
                success: (res) => {
                 console.log(res)
                 that.setData({ checked: true });
                }
              })
      },
    onChang({ detail }) {
        var that = this;
        // 需要手动对 checked 状态进行更新
        wx.authorize({
            scope: 'scope.writePhotosAlbum',
            success: () => { //用户允许授权，保存到相册
                that.setData({ checke: true });
            }})
      },
    onChan({ detail }) {
        var that = this;
        // 需要手动对 checked 状态进行更新
        wx.authorize({
            scope: 'scope.record',
            success() {
                //第一次成功授权后 状态切换为2
                that.setData({ check: true });
                // 用户已经同意小程序使用录音功能，后续调用 wx.startRecord 接口不会弹窗询问
                // wx.startRecord();
            }})
      },
    onCha({ detail }) {
        var that = this;
        // 需要手动对 checked 状态进行更新
            wx.authorize({
                scope: 'scope.addPhoneContact',
                success: (res) => {
                 console.log(res)
                 that.setData({ chec: true });
                }
              })
      },
    onCh({ detail }) {
        var that = this;
        // 需要手动对 checked 状态进行更新
        wx.authorize({
            scope: 'scope.camera',
            success: (res) => {
             console.log(res)
             that.setData({ che: true });
            }
          })
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this
        wx.getSetting({
            success (res) {
              console.log(res.authSetting)
              if(res.authSetting['scope.userLocation']){
                that.setData({ checked: true });
              }
              if(res.authSetting['scope.writePhotosAlbum']){
                that.setData({ checke: true });
              }
              if(res.authSetting['scope.record']){
                that.setData({ check: true });
              }
              if(res.authSetting['scope.addPhoneContact']){
                that.setData({ chec: true });
            }
            if(res.authSetting['scope.camera']){
                that.setData({ che: true });
            }
            }
          })

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})